package com.ibeeking.found.upms.s.rest.service.impl;

import com.ibeeking.found.upms.s.rest.service.IShopRolePermissionService;
import com.ibeeking.found.upms.s.rest.service.IShopRoleService;
import com.ibeeking.found.upms.service.common.bo.ShopRolePermissionBO;
import com.ibeeking.found.upms.service.common.dos.ShopRolePermissionDO;
import com.ibeeking.found.upms.service.mapper.ShopRolePermissionMapper;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.json.JsonUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ShopRolePermissionServiceImpl
 * @Description
 * @Author ibeeking
 * @Date 2021-02-22 12:24
 **/
@Service
public class ShopRolePermissionServiceImpl implements IShopRolePermissionService {

    @Resource
    private ShopRolePermissionMapper shopRolePermissionMapper;
    @Resource
    private IShopRoleService roleServiceImpl;

    @Override
    public List<ShopRolePermissionBO> queryRolePermissionByRoleId(Long roleId) {
        List<ShopRolePermissionDO> rolePermissionDos = shopRolePermissionMapper.selectList(new LambdaQueryWrapper<>(ShopRolePermissionDO.class)
                .eq(ShopRolePermissionDO::getRoleId, roleId)
        );
        return JsonUtils.jsonToList(rolePermissionDos, ShopRolePermissionBO.class);
    }

    @Override
    public List<ShopRolePermissionBO> queryRolePermissionByRoleIds(List<Long> roleIds) {
        if (Collections3.isEmpty(roleIds)) {
            return Collections3.emptyList();
        }
        List<ShopRolePermissionDO> rolePermissionDos = shopRolePermissionMapper.selectList(new LambdaQueryWrapper<>(ShopRolePermissionDO.class)
                .in(ShopRolePermissionDO::getRoleId, roleIds)
        );
        return JsonUtils.jsonToList(rolePermissionDos, ShopRolePermissionBO.class);
    }

    @Override
    public List<ShopRolePermissionBO> queryRolePermissionByPermissionId(Long permissionId) {
        List<ShopRolePermissionDO> rolePermissionDos = shopRolePermissionMapper.selectList(new LambdaQueryWrapper<>(ShopRolePermissionDO.class)
                .eq(ShopRolePermissionDO::getPermissionId, permissionId)
        );
        return JsonUtils.jsonToList(rolePermissionDos, ShopRolePermissionBO.class);
    }
}
